﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;


namespace CinemaSystem
{
    public partial class DengluForm : Form
    {
        public DengluForm()
        {
            InitializeComponent();

        }

        public string sqlstr;
        private void Form1_Load(object sender, EventArgs e)
        {
            zhuce.Visible = false;
            denglu.Visible = true;
            phone.Visible = false;
            txtemail.Visible = false;
            txtYangzheng.Visible = false;
            lkbYangzheng.Visible = false;
            skinEngine1.SkinFile = System.Environment.CurrentDirectory + "\\Skins\\Wave.ssk";

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {



        }

        private void txtLogin_Enter(object sender, EventArgs e)
        {

        }

     

        private void txtLogin_Click(object sender, EventArgs e)
        {
            txtLogin.Text = "";
            txtLogin.ForeColor = Color.Black;
        }

        private void txtpswd_Click(object sender, EventArgs e)
        {
          
        }

        private void btndenglu_Click(object sender, EventArgs e)
        {
            lkbwangji.Visible = true;
            zhuce.Visible = false;
            denglu.Visible = true;
            phone.Visible = false;
            txtemail.Visible = false;
            btndenglu.BackColor = Color.Gray;
            btnzhuce.BackColor = Color.Black;
            lkbwangji.Visible = true;
            txtYangzheng.Visible = false;
            lkbYangzheng.Visible = false;
        
            txtLogin.ForeColor = Color.Gray;
            txtpwd.ForeColor = Color.Gray;
            txtLogin.Text = "账号";
            txtpwd.Text = "密码";
     
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void GuanBi_Click(object sender, EventArgs e)
        {
            DengluForm Dl=new DengluForm ();
            Dl.Show();
            this.Close();
        }

        private void btnzhuce_Click(object sender, EventArgs e)
        {
            lkbwangji.Visible = false;
            zhuce.Visible = true;
            denglu.Visible = false;
            phone.Visible = true;
            txtemail.Visible = true;
            btndenglu.BackColor = Color.Black;
            btnzhuce.BackColor = Color.Gray;
            txtYangzheng.Visible = true;
            lkbYangzheng.Visible = true;
            txtLogin.Text = "账号";
            txtpwd.Text = "密码";
            txtemail.ForeColor = Color.Gray;
            phone.ForeColor = Color.Gray;
            txtemail.Text = "邮箱";
            phone.Text = "手机号";
        }
        /// <summary>
        /// 控件消失
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void phone_Leave(object sender, EventArgs e)
        {
            phone.Visible = false;
        }
        private void email_Leave(object sender, EventArgs e)
        {
            txtemail.Visible = false;
        }
      
        //文本控件的样式以及功能
        private void phone_Click(object sender, EventArgs e)
        {
            phone.Text = "";
            phone.ForeColor = Color.Black;
        }

        private void email_Click(object sender, EventArgs e)
        {
            txtemail.Text = "";
            txtemail.ForeColor = Color.Black;
        }

  
      
        private void MainForm_Activated(object sender, EventArgs e)
        {
            btndenglu.Focus();
        }
        
        public static string yuan;
        public static int hao;
        private void zhuce_Click(object sender, EventArgs e)
        {
               
            string sqlstr;
            sqlstr = string.Empty;
            if (txtLogin.Text == "" ||txtpwd.Text == "" || txtemail.Text == "" || phone.Text == ""|| txtYangzheng.Text=="")
            {
                MessageBox.Show("信息填写不完整！");
            }
            else
            {
                sqlstr = string.Format("insert into [User] values('{0}','{1}','{2}','{3}')",txtLogin.Text,txtpwd.Text,txtemail.Text,phone.Text);
                int i = DBHelper.ExecuteNonQuery(sqlstr);
                if (i > 0)
                {
                    if (txtYangzheng.Text== lkbYangzheng.Text)
                    {
                        MessageBox.Show("注册成功！");
                    }
                    else
                    {
                        MessageBox.Show("验证码不正确！");
                    }
                   
                }
                else
                {
                    MessageBox.Show("注册失败！");
                }
            }
        }
        //登录按钮的功能
        public static string yong;
        private void denglu_Click(object sender, EventArgs e)
        {
            string sqlstr = string.Format("select Userid,Userpwd from [User] where Userid='{0}'and  Userpwd='{1}'", txtLogin.Text,txtpwd.Text);
            DataTable dt =DBHelper.GetDataTable(sqlstr);
           if (dt.Rows.Count >0)
            {
                MainForm MF = new MainForm();
                MF.Show();
            this.Hide();
                yong = txtLogin.Text;
                yuan = txtpwd.Text;
                hao = int.Parse(yong);
            }
           else
           {
                MessageBox.Show("账号或密码错误！");
           }
        }
         
        private void txtLogin_TextChanged_1(object sender, EventArgs e)
        {

        }

        private void yanzheng_TextChanged(object sender, EventArgs e)
        {

        }

        private void lkbYangzheng_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

            Random rd = new Random();
            lkbYangzheng.Text = rd.Next(1000, 9999).ToString();


        }
        Boolean text1 = false;

        private void txtpwd_Leave(object sender, EventArgs e)
        {
            if (txtpwd.Text == "")
            {
                txtpwd.Text = "密码";
                txtpwd.ForeColor = Color.Gray;
                text1 = false;
                txtpwd.PasswordChar = '*';
            }
            else
            {
               text1= true;
            }
        }

        private void txtpwd_Enter(object sender, EventArgs e)
        {
            if (text1 == false)
            {
                txtpwd.Text ="";
                txtpwd.PasswordChar = (char)42;
                txtpwd.ForeColor = Color.Black;
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            guali guali = new guali();
            guali.Show();
            this.Hide();
        }
    }
}
